Welcome back for the 8th day of the #packagecalendar, The package of the day is globe4r created by John (JP) Coene. The globe4r package wraps the globe.gl library.
The package is not yet on CRAN and can be downloaded from Github with
remotes::install_github("JohnCoene/globe4r")
The package is wonderfully simple. Simply start by calling create_globe(). This will create a blank canvas with a globe on it.
library(globe4r)
create_globe()
it is interactive so you can zoom and drag as you wish.
Let’s play around a little bit and load in some population data. Population data is very important for Santa when we need to plan his route.
data("population") # comes with globe4r
Let’s take our globe we created with create_globe() and add some bars. This is done in much the same way as in ggplot2.
create_globe() %>%
globe_bars(
coords(lat, lon, altitude = value),
data = population
) %>%
scale_bars_altitude(max = 0.4)
It looks very nice! let’s just give it a little more of a blueish color. Luckily that is the default colors for globe4r so we just follow in the footsteps of before to add a color aesthetic.
create_globe() %>%
globe_bars(
coords(lat, lon, altitude = value, color = value),
data = population
) %>%
scale_bars_altitude(max = 0.4) %>%
scale_bars_color()
There are many more things you can do with globe4r! Please visit the website and the original library for more inspiration.
Setting background color
create_globe() will by default use a black background color. I have secretly used globe_background(color = "#2f3238") to set the background color equal to the page background color.